package org.six.background.controller;

import org.six.background.pojo.Shoptype;
import org.six.background.service.ShoptypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/shoptype")
public class ShoptypeController {
    @Autowired(required = false)
    private ShoptypeService shoptypeService;

    //商品分类查询
    @RequestMapping("/show")
    public List<Shoptype> show(){
        return shoptypeService.shoptypeshow();
    }

    //商品分类增加
    @RequestMapping("/add")
    public String shoptypeadd(Shoptype shoptype){
        int i = shoptypeService.shoptypeadd(shoptype);
        if(i>0&&i<2){
            return "ok";
        }else {
            return "no";
        }
    }

    //商品分类添加时检查名字是否重复
    @RequestMapping("/byname")
    public String shoptypeByname(String shoptypename){
        List <Shoptype> shoptypes = shoptypeService.shoptypeByname(shoptypename);
        if(shoptypes.isEmpty()){
            return "ok";
        }else {
            return "no";
        }
    }

    //商品分类删除
    @RequestMapping("/delete")
    public String shoptypedelete(Shoptype shoptype){
        int i = shoptypeService.shoptypedelete(shoptype);
        if(i>0&&i<2){
            return "ok";
        }else {
            return "no";
        }
    }

    //商品分类修改分类名
    @RequestMapping("/updata")
    public int shoptypeupdata(Shoptype shoptype){

            return shoptypeService.shoptypeupdata(shoptype);
    }

}
